#include "tcpserver.h"
#include "wowgetway.h"

TcpServer::TcpServer()
{
  //创建一个SOCKT
  m_TcpSocket = new QTcpSocket;
  //创建一个tcpServer
  m_TcpServer = new QTcpServer();

}

TcpServer::~TcpServer()
{
    delete m_TcpSocket;
    m_TcpSocket = nullptr;
    delete m_TcpServer;
    m_TcpServer = nullptr;
}

void TcpServer::NewTcpServer(quint16 port)
{
    wowGetway* m_wow = new wowGetway;
    bool sockt = m_TcpServer->listen(QHostAddress::Any , port);
    if(!sockt)
     {
       cout<<"创建，监听错误，请检查是否被占用"<<endl;;
     }
    else
    {
        cout<<"监听成功"<<endl;
        cout<<"当前监听端口为："<<m_wow->GetServerPort()<<endl;
    }
    delete m_wow;
    m_wow = nullptr;
}

QTcpSocket* TcpServer::NewTcpSocket()
{
    m_TcpSocket = m_TcpServer->nextPendingConnection();
    return m_TcpSocket;
}
